﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="XiTongRoles.aspx.cs" Inherits="PropertyAppraisal.SystemManage.XiTongRoles" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>角色管理</title>

    <link href="../jquery-easyui-1.3.5/themes/default/easyui.css" rel="stylesheet" />
    <link type="/text/css" href="../jquery-easyui-1.3.5/themes/icon.css" rel="stylesheet" />

    <%--<script type="text/javascript" src="easyui/js/jquery-1.8.0.min.js"></script>--%>

    <script type="text/javascript" src="../jquery-easyui-1.3.5/jquery-1.7.2-min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.3.5/easyloader.js"></script>

    <script type="text/javascript" src="../easyui/jquery.params.js"></script>
</head>
<body>
    <div>
        <%-- 模态窗 --%>
        <div style="margin: 20px 0;">
            <a href="javascript:void(0) " class="easyui-linkbutton" onclick="$('#trees').window('open')">分配权限</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#w').window('open')">添加角色</a>
            <%--	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#w').window('close')">Close</a>--%>
        </div>
        <%-- 添加角色--%>
        <div id="w" class="easyui-window" title="添加角色" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width: 500px; height: 200px; padding: 10px;">
            <form id="form1" runat="server">
                <table>
                    <tr>
                        <td>角色名称：</td>
                        <td>
                            <asp:TextBox ID="txtName" runat="server" class="easyui-validatebox" data-options="required:true"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>备注：</td>
                        <td>
                            <asp:TextBox ID="txtRamark" runat="server" TextMode="MultiLine" Height="54px"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <asp:Button ID="Button1" runat="server" Text="提交" BackColor="#00CC00" BorderStyle="None" Font-Bold="True" ForeColor="White" Height="26px" OnClick="Button1_Click" Width="69px" /></td>
                    </tr>
                </table>
            </form>
        </div>
        <%--   分配权限--%>
        <div id="trees" class="easyui-window" title="权限分配" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width: 500px; height: 200px; padding: 10px;">
            <ul id="tt"></ul>
        </div>
        <table id="ta" title="角色列表" style="width: 800px; height: 300px" data-options="
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10">
            <thead>
                <tr>
                    <th field="chek" width="50"></th>
                    <th field="inv" width="100">角色</th>
                    <th field="date" width="200">备注</th>
                    <th field="name" width="100">是否启用</th>
                    <th field="amount" width="200">操作</th>
                </tr>
            </thead>
        </table>
    </div>



    <script>
        //iframe操作主页面
        //$(function () {
        //    $('.cc').bind("click", function () {
        //        parent.$('#wu-tabs').tabs("add", {
        //            title: $(this).text(),
        //            content: '<iframe  src="SystemManage/XiTongAuthtority.aspx" frameBorder="0" border="0"  style="width: 100%; height: 100%;" noResize/>',
        //            iconCls: $(this).attr('data-icon'),
        //            closable: true
        //        });
        //    })
        //})
        function dengji() {
            parent.addTab("分配权限", "/SystemManage/XiTongAuthtority.aspx", "", true);
        }

        //表格
        function getData() {
            var rows = [];
            $.ajax({
                type: "post", //要用post方式                 
                url: "XiTongRoles.aspx/showRole",//方法所在页面和方法名
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,
                success: function (result) {
                    var json = eval("(" + result.d + ")");
                    for (var i = 0; i < json.length; i++) {
                        rows.push({
                            chek: '<input type="checkbox" value="1"/>',
                            inv: json[i].roles_Name,
                            date: json[i].roles_Remarks,
                            name: json[i].roles_IsState == 0 ? "启用" : "未启用",
                            amount: '<input type="button" onclick="delrole(this,' + json[i].roles_Id + ')" value="删除"/><input type="button" onclick="uptrole(' + json[i].roles_Id + ')"  value="修改"/><input type="button" value="停用" onclick="ting(' + json[i].roles_Id + ')"/><input type="button" value="启用" onclick="qi(' + json[i].roles_Id + ')"/>',
                        });
                    }
                }
            })
            return rows;
        }

        //function ting(id)
        //{

        //}



        //删除角色
        function delrole(obj,id) {
            $.ajax({
                type: "post",
                url: "XiTongRoles.aspx/DelRole",
                data: "{'roleid':'" + id + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,
                success:function(result)
                {
                    var json = eval("(" + result.d + ")");

                    if(json==1)
                    {
                        $.messager.alert("","删除成功！");
                        $(obj).parent().parent().parent().remove();
                    }
                    else
                    {
                        $.messager.alert("","删除失败！");
                    }
                }
            })
        }

        //修改角色
        function uptrole(id)
        {
            parent.addTab("修改角色", "/SystemManage/UpdateRole.aspx?id=" + id, "icon-chart-organisation", true);
        }


        function pagerFilter(data) {
            if (typeof data.length == 'number' && typeof data.splice == 'function') {	// is array
                data = {
                    total: data.length,
                    rows: data
                }
            }
            var dg = $(this);
            var opts = dg.datagrid('options');
            var pager = dg.datagrid('getPager');
            pager.pagination({
                onSelectPage: function (pageNum, pageSize) {
                    opts.pageNumber = pageNum;
                    opts.pageSize = pageSize;
                    pager.pagination('refresh', {
                        pageNumber: pageNum,
                        pageSize: pageSize
                    });
                    dg.datagrid('loadData', data);
                }
            });
            if (!data.originalRows) {
                data.originalRows = (data.rows);
            }
            var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
            var end = start + parseInt(opts.pageSize);
            data.rows = (data.originalRows.slice(start, end));
            return data;
        }

        $(function () {


            $('#ta').datagrid({ loadFilter: pagerFilter }).datagrid('loadData', getData());
        });


    </script>
</body>
</html>
